package edu.krazy.server.threads;

import java.io.IOException;
import java.net.ServerSocket;

import edu.krazy.server.KrazyClient;
import edu.krazy.server.KrazyServer;

public class AcceptClientThread extends Thread {
	
	private KrazyServer mServer;
	private ServerSocket mServerSocket;
	private boolean mRunning;
	
	public AcceptClientThread(KrazyServer server, int port){
		mServer = server;
		try {
			mServerSocket = new ServerSocket(port);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void run() {
		mRunning = true;
		while(mRunning){
			try {
				KrazyClient client = new KrazyClient(mServerSocket.accept());
				mServer.addClient(client);
				client.start();
			} catch (IOException e) {
				
				e.printStackTrace();
			}
		}
		
		super.run();
	}
	
	
}
